//
//  Team9ExpertDetailView.m
//  Team9Project
//
//  Created by 朱嘉祺 on 15/10/15.
//  Copyright © 2015年 apple. All rights reserved.
//

#import "Team9ExpertDetailView.h"
#import <Masonry.h>
#import "Team9Header.h"
#import "Team9ExpertPro_serviceModel.h"
#import "Team9BaseLabel.h"

@interface Team9ExpertDetailView ()
@property(nonatomic, strong) Team9BaseLabel *titleLabel;
@property(nonatomic, strong) Team9BaseLabel *footTitleLabel;
@property(nonatomic, strong) UILabel *locationLabel;
@property(nonatomic, strong) UILabel *costLabel;
@property(nonatomic, strong) UILabel *rangeLabel;
@property(nonatomic, strong) UILabel *stylesLabel;
@property(nonatomic, strong) UILabel *sloganLabel;
@property(nonatomic, strong) UILabel *bioLabel;

@end
@implementation Team9ExpertDetailView

- (instancetype)init{
    self = [super init];
    if (self) {
        [self createView];
    }
    return self;
}
- (void)createView{
    self.titleLabel = [[Team9BaseLabel alloc] initWith:LableColorTypeRedCyan];
    [self addSubview:_titleLabel];
    
    self.footTitleLabel = [[Team9BaseLabel alloc] initWith:LableColorTypeRedCyan];
    [self addSubview:_footTitleLabel];
    
    self.locationLabel = [UILabel new];
    [self addSubview:_locationLabel];
    
    self.costLabel = [UILabel new];
    [self addSubview:_costLabel];
    
    self.rangeLabel = [UILabel new];
    [self addSubview:_rangeLabel];
    
    self.stylesLabel = [UILabel new];
    [self addSubview:_stylesLabel];
    
    self.sloganLabel = [UILabel new];
    [self addSubview:_sloganLabel];
    
    self.bioLabel = [UILabel new];
    [self addSubview:_bioLabel];
    
    [self p_contrains];
    
    for (UIView *view in self.subviews) {
        if ([view isKindOfClass:[UILabel class]]) {
            UILabel *label = (UILabel *)view;
            label.font = [UIFont systemFontOfSize:12 * WIDTH / 375];
            if (![view isMemberOfClass:[Team9BaseLabel class]]) {
                label.textColor = [UIColor whiteColor];
            }
        }
    }
    
//    self.titleLabel.textColor = [UIColor redColor];
//    self.footTitleLabel.textColor = [UIColor redColor];
    self.titleLabel.text = @"关于";
    self.footTitleLabel.text = @"个人简历";
}
- (void)p_contrains{
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.centerX.equalTo(self).offset(10);
    }];
    UIView *lineView = [UIView new];
    [self addSubview:lineView];
    lineView.backgroundColor = [UIColor lightGrayColor];
    UIView *footLineView = [UIView new];
    [self addSubview:footLineView];
    footLineView.backgroundColor = [UIColor lightGrayColor];
    
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(10);
        make.width.equalTo(@(WIDTH - 20));
        make.height.equalTo(@1);
        make.centerX.equalTo(self);
    }];
    
    UILabel *locatinName = [UILabel new];
    [self addSubview:locatinName];
    
    UILabel *costName = [UILabel new];
    [self addSubview:costName];
    
    UILabel *rangeName = [UILabel new];
    [self addSubview:rangeName];
    
    UILabel *styleName = [UILabel new];
    [self addSubview:styleName];
    
    UILabel *sloganName = [UILabel new];
    [self addSubview:sloganName];
    
    locatinName.text = @"服务地区";
    costName.text = @"设计花费";
    rangeName.text = @"服务范围";
    styleName.text = @"设计风格";
    sloganName.text = @"人生格言";
    sloganName.numberOfLines = 0;
    
    [locatinName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lineView.mas_bottom).offset(10);
        make.left.equalTo(self).offset(10);
    }];
    [costName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(locatinName.mas_bottom).offset(10);
        make.left.equalTo(self).offset(10);
    }];
    [rangeName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(costName.mas_bottom).offset(10);
        make.left.equalTo(self).offset(10);
    }];
    [styleName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(rangeName.mas_bottom).offset(10);
        make.left.equalTo(self).offset(10);
    }];
    [sloganName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(styleName.mas_bottom).offset(10);
        make.left.equalTo(self).offset(10);
    }];
    
    [self.footTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.sloganLabel.mas_bottom).offset(10);
        make.centerX.equalTo(self);
    }];
    
    [self.locationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(locatinName);
        make.left.equalTo(costName.mas_right).offset(10);
    }];
    [self.costLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(costName);
        make.left.equalTo(costName.mas_right).offset(10);
    }];
    [self.rangeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(rangeName);
        make.left.equalTo(rangeName.mas_right).offset(10);
    }];
    [self.stylesLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(styleName);
        make.left.equalTo(styleName.mas_right).offset(10);
    }];
    self.sloganLabel.numberOfLines = 0;
    [self.sloganLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(sloganName.mas_bottom).offset(10);
        make.left.equalTo(self).offset(10).priorityHigh();
        make.right.equalTo(self).offset(-10);
    }];
    [footLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.footTitleLabel.mas_bottom).offset(10);
        make.width.equalTo(@(WIDTH - 20));
        make.height.equalTo(@1);
        make.centerX.equalTo(self);
//#warning test!
//        make.bottom.equalTo(self).offset(-10);
    }];
    self.bioLabel.numberOfLines = 0;
    [self.bioLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(footLineView.mas_bottom).offset(10);
        make.centerX.equalTo(self);
        make.width.equalTo(lineView);
        make.bottom.equalTo(self).offset(-10);
    }];
    
}
- (void)setModel:(Team9ExpertPro_serviceModel *)model
{
    if (_model != model) {
        _model = model;
    }
    self.locationLabel.text = self.model.location;
    self.costLabel.text = [NSString stringWithFormat:@"%@~%@万元", self.model.price_min, self.model.price_max];
    self.rangeLabel.text = [self stringByArray:self.model.services];
    self.stylesLabel.text = [self stringByArray:self.model.styles];
    self.bioLabel.text = self.model.bio;
    self.sloganLabel.text = self.model.slogan;

}
- (void)setString:(NSString *)string
{
    if (_string != string) {
        _string = string;
          self.titleLabel.text = [NSString stringWithFormat:@"关于%@", self.string];
    }
}
#pragma mark string mark by a array only with string
- (NSString *)stringByArray:(NSArray *)array{
    NSString *string = [NSString string];
    for (NSString *str in array) {
        string = [string stringByAppendingString:[NSString stringWithFormat:@"%@ ", str]];
    }
    return string;
}

@end
